<?php
	require_once ('searchProd.php');
	$list = search_prod ($catval);
	foreach ($list as $key=>$value){
		if ($key == 'tblno'){
			$tblno = $value;
		}
		if ($key == 'tbl'){
			$tbl = $value;
		}
		if ($key == 'path'){
			$path = $value;
		}
	}
	
	if ($tblno == '0' && $tbl == '0' && $path == '0'){ //if these 3 params are '0', it means that the product put in shopping cart is not a valid product
		//delete this product from shoplist table
		include ("conn.php");
		$del = "delete from shoplist where sessionid like '$shpid' and catNo like '$catval'";
		$del_res = mysql_query($del,$db);
		echo "<script language=javascript>alert('Catalog number $catval does not exist.');</script>";
	}else{
		$shpid = $_SESSION['id'];
		
		if ($path == 'conn.php'){
			include ("conn.php");
		}else{
			include ("connabm.php");
		}
		
		$sql = "select * from $tbl where catNo like '$catval'";
		$res = mysql_query($sql,$db);
		$rows = mysql_num_rows($res);
		if ($rows > 0){
			$r = mysql_fetch_array($res);
			$prodname = $r['pname'];
			$prodsize = $r['quantity'];
			$prodprice = $r['price'];
			$prodsupplier = $r['supplier'];
			
			//update shoplist table
			include ("conn.php");
			$spupd = "update shoplist set dbNo = '$tblno', pname = '$prodname', unit = '$prodsize', price = $prodprice, 
			supplier = '$prodsupplier' where sessionid like '$shpid' and catNo like '$catval'";
			$spupd_res = mysql_query($spupd,$db);
			
		}
	}
	
?>